//
//  WHNView.m
//  城市
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 Hner. All rights reserved.
//

#import "WHNView.h"

@interface WHNView ()

@end

@implementation WHNView

-(UIImageView *)WHNBackImageView
{
    if (!_WHNBackImageView) {
        _WHNBackImageView = [[UIImageView alloc]init];
        [self addSubview:_WHNBackImageView];
    }
    return _WHNBackImageView;
}
-(UIImageView *)WHNCenterImageView
{
    if (!_WHNCenterImageView) {
        _WHNCenterImageView = [[UIImageView alloc]init];
        [self addSubview:_WHNCenterImageView];
    }
    return _WHNCenterImageView;
}
-(UILabel *)TitleLabel
{
    if (!_TitleLabel) {
        _TitleLabel = [[UILabel alloc]init];
        [_TitleLabel NightWithType:UIViewColorTypeClear];
        [self addSubview:_TitleLabel];
    }
    return _TitleLabel;
}
-(UILabel *)AnchorLabel
{
    if (!_AnchorLabel) {
        _AnchorLabel = [[UILabel alloc]init];
        [_AnchorLabel NightWithType:UIViewColorTypeClear];
        [self addSubview:_AnchorLabel];
    }
    return _AnchorLabel;
}
-(UILabel *)TimeLabel
{
    if (!_TimeLabel) {
        _TimeLabel = [[UILabel alloc]init];
        [_TimeLabel NightWithType:UIViewColorTypeClear];
        [self addSubview:_TimeLabel];
    }
    return _TimeLabel;
}
-(UIButton *)WHNListButton
{
    if (!_WHNListButton) {
        _WHNListButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_WHNListButton];
    }
    return _WHNListButton;
}
-(UIButton *)WHNLeftButton
{
    if (!_WHNLeftButton) {
        _WHNLeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_WHNLeftButton];
    }
    return _WHNLeftButton;
}
-(UIButton *)WHNPlayButton
{
    if (!_WHNPlayButton) {
        _WHNPlayButton = [[WHNButton alloc] init];
        [_WHNPlayButton addTarget:self action:@selector(clickedAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_WHNPlayButton];
    }
    return _WHNPlayButton;
}
-(UIButton *)WHNRightButton
{
    if (!_WHNRightButton) {
        _WHNRightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_WHNRightButton];
    }
    return _WHNRightButton;
}
-(UIButton *)WHNHistoryButton
{
    if (!_WHNHistoryButton) {
        _WHNHistoryButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_WHNHistoryButton];
    }
    return _WHNHistoryButton;
}
-(UISegmentedControl *)WHNSegment
{
    if (!_WHNSegment) {
        _WHNSegment = [[UISegmentedControl alloc]initWithItems:@[@"昨天", @"今天", @"明天"]];
        [self addSubview:_WHNSegment];
    }
    return _WHNSegment;
}
-(UILabel *)ChangeTime
{
    if (!_ChangeTime) {
        _ChangeTime = [[UILabel alloc] init];
        [_ChangeTime NightWithType:UIViewColorTypeClear];
        [self addSubview:_ChangeTime];
    }
    return _ChangeTime;
}
-(UILabel *)LongTime
{
    if (!_LongTime) {
        _LongTime = [[UILabel alloc] init];
        [_LongTime NightWithType:UIViewColorTypeClear];
        [self addSubview:_LongTime];
    }
    return _LongTime;
}
-(UIProgressView *)WHNSlider
{
    if (!_WHNSlider) {
        _WHNSlider = [[UIProgressView alloc]init];
//        [_WHNSlider setThumbImage:[UIImage imageNamed:@"sanjiao1"] forState:UIControlStateNormal];
        [self addSubview:_WHNSlider];
    }
    return _WHNSlider;
}
-(UIView *)BlackView
{
    if (!_BlackView) {
        _BlackView = [[UIView alloc]init];
        [self addSubview:_BlackView];
    }
    return _BlackView;
}
-(UILabel *)UserLabel
{
    if (!_UserLabel) {
        _UserLabel = [[UILabel alloc]init];
        [self addSubview:_UserLabel];
    }
    return _UserLabel;
}
-(UILabel *)IndexLabel
{
    if (!_IndexLabel) {
        _IndexLabel = [[UILabel alloc]init];
        [self addSubview:_IndexLabel];
    }
    return _IndexLabel;
}
-(UILabel *)AttentionLabel
{
    if (!_AttentionLabel) {
        _AttentionLabel = [[UILabel alloc]init];
        [self addSubview:_AttentionLabel];
    }
    return _AttentionLabel;
}
-(UILabel *)NumberLabel1
{
    if (!_NumberLabel1) {
        _NumberLabel1 = [[UILabel alloc]init];
        [self addSubview:_NumberLabel1];
    }
    return _NumberLabel1;
}
-(UILabel *)FanLabel
{
    if (!_FanLabel) {
        _FanLabel = [[UILabel alloc]init];
        [self addSubview:_FanLabel];
    }
    return _FanLabel;
}
-(UILabel *)NumberLabel2
{
    if (!_NumberLabel2) {
        _NumberLabel2 = [[UILabel alloc]init];
        [self addSubview:_NumberLabel2];
    }
    return _NumberLabel2;
}
-(UILabel *)ZanLabel
{
    if (!_ZanLabel) {
        _ZanLabel = [[UILabel alloc]init];
        [self addSubview:_ZanLabel];
    }
    return _ZanLabel;
}
-(UILabel *)NumberLabel3
{
    if (!_NumberLabel3) {
        _NumberLabel3 = [[UILabel alloc]init];
        [self addSubview:_NumberLabel3];
    }
    return _NumberLabel3;
}
-(UILabel *)LineLabel1
{
    if (!_LineLabel1) {
        _LineLabel1 = [[UILabel alloc]init];
        [self addSubview:_LineLabel1];
    }
    return _LineLabel1;
}
-(UILabel *)LineLabel2
{
    if (!_LineLabel2) {
        _LineLabel2 = [[UILabel alloc]init];
        [self addSubview:_LineLabel2];
    }
    return _LineLabel2;
}
-(UIImageView *)DownImageView
{
    if (!_DownImageView) {
        _DownImageView = [[UIImageView alloc]init];
        [self addSubview:_DownImageView];
    }
    return _DownImageView;
}

-(void)setKind:(WHNViewKind)kind
{
    if (_kind != kind) {
        _kind = kind;
    }
    switch (kind) {
        case WHNViewKindLabelLive:
            self.WHNBackImageView.frame = CGRectMake(0, 0, ScreenWidth, self.frame.size.height);
            self.BlackView.frame = CGRectMake(0, 0, _WHNBackImageView.frame.size.width, _WHNBackImageView.frame.size.height);
            self.BlackView.backgroundColor = [UIColor colorWithRed:0.06 green:0.25 blue:0.48 alpha:1];
            self.BlackView.alpha = .5;

            self.WHNCenterImageView.frame = CGRectMake(40 * FitWidth, 114 * FitHeight, _WHNBackImageView.frame.size.width - 80 * FitHeight, _WHNBackImageView.frame.size.width - 80 * FitHeight);
            _WHNCenterImageView.layer.cornerRadius = 40 * FitHeight;
            _WHNCenterImageView.layer.masksToBounds = YES;
            
            self.TitleLabel.frame = CGRectMake(_WHNCenterImageView.frame.origin.x, _WHNCenterImageView.frame.origin.y + 100 * FitHeight, _WHNCenterImageView.frame.size.width, 40 * FitHeight);
            self.TitleLabel.textAlignment = 1;
            self.AnchorLabel.frame = CGRectMake(_TitleLabel.frame.origin.x, _TitleLabel.frame.origin.y + _TitleLabel.frame.size.height + 5 * FitHeight, _TitleLabel.frame.size.width, 20 * FitHeight);
            self.AnchorLabel.textAlignment = 1;
            self.TimeLabel.frame = CGRectMake(_AnchorLabel.frame.origin.x, (_AnchorLabel.frame.origin.y + _AnchorLabel.frame.size.height + 5 )* FitHeight, _AnchorLabel.frame.size.width, _AnchorLabel.frame.size.height);
            self.TimeLabel.textAlignment = 1;
            self.WHNListButton.frame = CGRectMake(12.5 * FitWidth, _WHNCenterImageView.frame.origin.y + _WHNCenterImageView.frame.size.height + 50 * FitHeight, 40 * FitHeight, 40 * FitHeight);
            self.WHNLeftButton.frame = CGRectMake(_WHNListButton.frame.origin.x + _WHNListButton.frame.size.width + 40 * FitWidth, _WHNListButton.frame.origin.y + 5 * FitHeight, 30 * FitHeight, 30 * FitHeight);
            self.WHNPlayButton.frame = CGRectMake(_WHNLeftButton.frame.origin.x + _WHNLeftButton.frame.size.width + 35 * FitWidth, _WHNLeftButton.frame.origin.y - 15 * FitHeight, 60 * FitHeight, 60 * FitHeight);
            self.WHNRightButton.frame = CGRectMake(_WHNPlayButton.frame.origin.x + _WHNPlayButton.frame.size.width + 35 * FitWidth, _WHNLeftButton.frame.origin.y, _WHNLeftButton.frame.size.width, _WHNLeftButton.frame.size.height);
            self.WHNHistoryButton.frame = CGRectMake(_WHNRightButton.frame.origin.x + _WHNRightButton.frame.size.width + 40 * FitWidth, _WHNListButton.frame.origin.y , _WHNListButton.frame.size.width, _WHNListButton.frame.size.height);
            self.ChangeTime.frame = CGRectMake(0, _WHNListButton.frame.origin.y + _WHNListButton.frame.size.height + 20 * FitHeight, 187.5 * FitWidth, 20 * FitHeight);
            self.LongTime.frame = CGRectMake(_ChangeTime.frame.origin.x + _ChangeTime.frame.size.width, _ChangeTime.frame.origin.y, self.frame.size.width - _ChangeTime.frame.size.width, _ChangeTime.frame.size.height);
            self.LongTime.textAlignment = 2;
            self.WHNSlider.frame = CGRectMake(0, _ChangeTime.frame.origin.y + _ChangeTime.frame.size.height, self.frame.size.width, 20 * FitHeight);
            
            [self.WHNListButton setImage:[UIImage imageNamed:@"f_menu"] forState:UIControlStateNormal];
            [self.WHNLeftButton setImage:[UIImage imageNamed:@"shangyishou"] forState:UIControlStateNormal];
            [self.WHNRightButton setImage:[UIImage imageNamed:@"xiayishou"] forState:UIControlStateNormal];
            [self.WHNHistoryButton setImage:[UIImage imageNamed:@"f_time"] forState:UIControlStateNormal];
            break;
        case WHNViewKindSegmentControl:
            self.WHNBackImageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
            self.WHNBackImageView.backgroundColor = [UIColor colorWithRed:0.57 green:0.66 blue:0.77 alpha:1];
            self.WHNBackImageView.alpha = .5;
            self.WHNSegment.frame = CGRectMake(10 * FitWidth, 0, self.frame.size.width - 20 * FitWidth, 40 * FitHeight);
            _WHNSegment.tintColor = [UIColor whiteColor];
            break;
        case WHNViewKindPictureTopList:
            self.WHNBackImageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
            self.WHNCenterImageView.frame = CGRectMake(60 * FitWidth, 100 * FitHeight, self.frame.size.width - 120 * FitHeight, self.frame.size.width - 120 * FitHeight);
            _WHNCenterImageView.layer.cornerRadius = 40 * FitHeight;
            _WHNCenterImageView.layer.masksToBounds = YES;
            self.ChangeTime.frame = CGRectMake(0, _WHNCenterImageView.frame.origin.y + _WHNCenterImageView.frame.size.height + 40 * FitHeight, 187.5 * FitWidth, 20 * FitHeight);
            self.LongTime.frame = CGRectMake(_ChangeTime.frame.origin.x + _ChangeTime.frame.size.width, _ChangeTime.frame.origin.y, self.frame.size.width - _ChangeTime.frame.size.width, _ChangeTime.frame.size.height);
            self.LongTime.textAlignment = 2;
            self.WHNSlider.frame = CGRectMake(0, _ChangeTime.frame.origin.y + _ChangeTime.frame.size.height, self.frame.size.width, 20 * FitHeight);
            
            self.WHNListButton.frame = CGRectMake(12.5 * FitWidth, _WHNSlider.frame.origin.y + _WHNSlider.frame.size.height + 20 * FitHeight, 40 * FitHeight, 40 * FitHeight);
            self.WHNLeftButton.frame = CGRectMake(_WHNListButton.frame.origin.x + _WHNListButton.frame.size.width + 45 * FitWidth, _WHNListButton.frame.origin.y + 5 * FitHeight, 30 * FitHeight, 30 * FitHeight);
            self.WHNPlayButton.frame = CGRectMake(_WHNLeftButton.frame.origin.x + _WHNLeftButton.frame.size.width + 35 * FitWidth, _WHNLeftButton.frame.origin.y - 10 * FitHeight, 50 * FitHeight, 50 * FitHeight);
            self.WHNRightButton.frame = CGRectMake(_WHNPlayButton.frame.origin.x + _WHNPlayButton.frame.size.width + 35 * FitWidth, _WHNLeftButton.frame.origin.y, _WHNLeftButton.frame.size.width, _WHNLeftButton.frame.size.height);
            self.WHNHistoryButton.frame = CGRectMake(_WHNRightButton.frame.origin.x + _WHNRightButton.frame.size.width + 45 * FitWidth, _WHNListButton.frame.origin.y , _WHNListButton.frame.size.width, _WHNListButton.frame.size.height);
            
            [self.WHNListButton setImage:[UIImage imageNamed:@"f_menu"] forState:UIControlStateNormal];
            [self.WHNLeftButton setImage:[UIImage imageNamed:@"shangyishou"] forState:UIControlStateNormal];
            [self.WHNRightButton setImage:[UIImage imageNamed:@"xiayishou"] forState:UIControlStateNormal];
            [self.WHNHistoryButton setImage:[UIImage imageNamed:@"f_time"] forState:UIControlStateNormal];
            
            break;
        case WHNViewKindDownDetails:
            self.WHNBackImageView.frame = CGRectMake(0, 0, ScreenWidth, self.frame.size.height);
            self.WHNCenterImageView.frame = CGRectMake(10 * FitWidth, 20 * FitHeight, 70 * FitHeight, 70 * FitHeight);
            self.TitleLabel.frame = CGRectMake(_WHNCenterImageView.frame.origin.x + _WHNCenterImageView.frame.size.width + 10 * FitWidth, _WHNCenterImageView.frame.origin.y, self.frame.size.width - _WHNCenterImageView.frame.size.width - 100 * FitWidth, 30 * FitHeight);
            self.AnchorLabel.frame = CGRectMake(_TitleLabel.frame.origin.x, _TitleLabel.frame.origin.y + _TitleLabel.frame.size.height + 10 * FitHeight, _TitleLabel.frame.size.width, _TitleLabel.frame.size.height);
            self.TimeLabel.frame = CGRectMake(_TitleLabel.frame.origin.x + _TitleLabel.frame.size.width, _TitleLabel.frame.origin.y + _TitleLabel.frame.size.height, 70 * FitWidth, 10 * FitHeight);
            break;
        case WHNViewKindTopUserInfo:
            self.WHNBackImageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
            self.BlackView.frame = CGRectMake(0, 0, _WHNBackImageView.frame.size.width, _WHNBackImageView.frame.size.height);
            _BlackView.backgroundColor = [UIColor blackColor];
            _BlackView.alpha = .5;

            self.WHNCenterImageView.frame = CGRectMake(150 * FitWidth, 40 * FitHeight, 75 * FitHeight, 75 * FitHeight);
            _WHNCenterImageView.layer.cornerRadius = 75 * FitHeight / 2;

            _WHNCenterImageView.layer.masksToBounds = YES;
            _WHNCenterImageView.layer.borderWidth = 2.0;
            _WHNCenterImageView.layer.borderColor = [UIColor whiteColor].CGColor;
            self.UserLabel.frame = CGRectMake(60 * FitWidth, _WHNCenterImageView.frame.origin.y + _WHNCenterImageView.frame.size.height + 10 * FitHeight, 255 * FitWidth, 20 * FitHeight);
            _UserLabel.textAlignment = 1;
            _UserLabel.textColor = [UIColor whiteColor];
            self.IndexLabel.frame = CGRectMake(_UserLabel.frame.origin.x, _UserLabel.frame.origin.y + _UserLabel.frame.size.height + 10 * FitHeight, _UserLabel.frame.size.width, _UserLabel.frame.size.height);
            _IndexLabel.textAlignment = 1;
            _IndexLabel.textColor = [UIColor whiteColor];
            self.AttentionLabel.frame = CGRectMake(0, _IndexLabel.frame.origin.y + _IndexLabel.frame.size.height + 20 * FitHeight, 375 * FitWidth / 3, 20 * FitHeight);
            _AttentionLabel.text = @"关注的人";
            _AttentionLabel.textAlignment = 1;
            _AttentionLabel.textColor = [UIColor whiteColor];
            self.NumberLabel1.frame = CGRectMake(0, _AttentionLabel.frame.origin.y + _AttentionLabel.frame.size.height, _AttentionLabel.frame.size.width, _AttentionLabel.frame.size.height);
            _NumberLabel1.textAlignment = 1;
            _NumberLabel1.textColor = [UIColor whiteColor];
            self.LineLabel1.frame = CGRectMake(_AttentionLabel.frame.origin.x + _AttentionLabel.frame.size.width, _AttentionLabel.frame.origin.y, 1, _AttentionLabel.frame.size.height * 2);
            _LineLabel1.backgroundColor = [UIColor whiteColor];
            self.FanLabel.frame = CGRectMake(_AttentionLabel.frame.origin.x + _AttentionLabel.frame.size.width, _AttentionLabel.frame.origin.y, _AttentionLabel.frame.size.width, _AttentionLabel.frame.size.height);
            _FanLabel.text = @"粉丝";
            _FanLabel.textAlignment = 1;
            _FanLabel.textColor = [UIColor whiteColor];
            self.NumberLabel2.frame = CGRectMake(_FanLabel.frame.origin.x, _FanLabel.frame.origin.y + _FanLabel.frame.size.height, _FanLabel.frame.size.width, _FanLabel.frame.size.height);
            _NumberLabel2.textAlignment = 1;
            _NumberLabel2.textColor = [UIColor whiteColor];
            self.LineLabel2.frame = CGRectMake(_FanLabel.frame.origin.x + _FanLabel.frame.size.width, _FanLabel.frame.origin.y, _LineLabel1.frame.size.width, _LineLabel1.frame.size.height);
            _LineLabel2.backgroundColor = [UIColor whiteColor];
            self.ZanLabel.frame = CGRectMake(_FanLabel.frame.origin.x + _FanLabel.frame.size.width, _FanLabel.frame.origin.y, _FanLabel.frame.size.width, _FanLabel.frame.size.height);
            _ZanLabel.text = @"赞过的";
            _ZanLabel.textAlignment = 1;
            _ZanLabel.textColor = [UIColor whiteColor];
            self.NumberLabel3.frame = CGRectMake(_ZanLabel.frame.origin.x, _ZanLabel.frame.origin.y + _ZanLabel.frame.size.height, _ZanLabel.frame.size.width, _ZanLabel.frame.size.height);
            _NumberLabel3.textAlignment = 1;
            _NumberLabel3.textColor = [UIColor whiteColor];
            
            break;
        default:
            break;
    }
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self NightWithType:UIViewColorTypeNormal];
    }
    return self;
}


- (void)clickedAction {
    self.WHNPlayButton.selected = !self.WHNPlayButton.selected;
    [self.delegate passValue:self.WHNPlayButton.selected];
}

@end
